<template>
	<view class="package response" v-for="(item) in orderList" :key='item.id' 
	@click="navTo('groupBenefits/groupDetails?id='+item.id)" style="margin:0px auto 15rpx;">
		<view>
			<view class="center space-between ">
				<view class="direction-start polp" style="margin-top: 0px;">
					<view>{{item.title}}</view>
					<view class="center" style="width: 100%;">
						<text>创建人</text>
						<image :src="item.avatar" mode=""></image> 
						<text>{{item.nickname}}</text>
					</view>
				</view>
				<view class="direction-start" style="align-items: flex-end;" >
					<image class="polpImg" :src="Expired" mode="" v-if="item.bao_status=='2'"></image>
					<text style="color: #666;font-size: 20rpx;" v-if="item.bao_status=='2'">{{item.descript}}</text>
					<text  v-if="item.status=='0'" style="color:#1B91FF">未支付</text>
				</view>
			</view>
			<shopList :type="'subsidy'" :shoppAll="item.goods_list"></shopList>
			<view class="Paid center">
				<view><text>实付</text></view>
			    <view style="margin: 0px 15rpx;"><text>¥ </text><text>{{item.money}}</text></view>
				<view style="color: #F54B39;font-size: 20rpx;margin-top: 10rpx;" v-if="item.jia_text">{{item.jia_text}}</view>
			</view>
			<view class="center group">
				<view><text>我分享的车友团获得奖励</text></view>
			    <view style="margin-left: 20rpx;"><text>¥</text><text>{{item.jiang_list[0].money}}</text></view>
			</view>
			<view class="space-between copys" v-if="item.bao_status=='2'" >  
				<view></view>
			    <view @click.stop="Onekey(item.bao_id)">复制同款</view>
			</view>
		</view>
	</view>
	<!-- 新建团惠包弹框 -->
	<uni-popup ref="PobulicePopup" type="center" :is-mask-click="false">
	 <pobulice :title="'温馨提示'" :text="text" @close="closeBankPad" @submit="submit" :type="'center'"></pobulice>
	</uni-popup>
</template>

<script setup lang="ts">
import { navTo } from '@/utils/navigator';
import shopList from '@c/order/shopList.vue';
import { onShow } from '@dcloudio/uni-app';
import pobulice from '@c/pobulic/public.vue';
import { errorToast, successToast, showLoading } from '@/utils/prompt';
import { numsTeam } from '@/gql/group';
import { Expired } from '@/utils/Static';
import { toPublish } from '@mqtt';
import { ref } from 'vue';
import { getDriverID } from '@/stores/driverID';
const user_id = getDriverID();
const groupList = ref();
const borId = ref('');
const PobulicePopup = ref(null);
const repeat = ref(true); //放重复点击
const text = '您当前有正在创建新的团惠包  如果继续您新的团惠包内容将被覆盖';
const props = defineProps({
  orderList: { type: Array },
});
function changes(num, isShow) {
  props.orderList.map((item, index) => {
    if (index == num) {
      item.is_show = isShow == 1 ? 2 : 1;
    }
  });
}
onShow(() => {
  cartTeams();
});
/**
 * 获取团惠包数量
 */
function cartTeams() {
  const payload = {
    query: numsTeam,
    variables: {
      user_id,
    },
  };
  toPublish('ql/store/getCartTeamList', payload, (obj: any) => {
    const { team_shopping_nums } = obj.data;
    groupList.value = team_shopping_nums.nums;
  });
}
function Onekey(id) {
  borId.value = id;
  if (groupList.value < 1) {
    addGroup();
  } else {
    openBankPad();
  }
}
/**
 * 删除当前团惠包购物车
 */
function submit() {
  showLoading();
  if (!repeat.value) {
    return;
  }
  repeat.value = false;
  const payload = {
    user_id,
  };
  toPublish('store/clearTeamCart', payload, (obj: any) => {
    const { code, msg } = obj;
    closeBankPad();
    if (code === 1) {
      repeat.value = true;
      addGroup();
    } else {
      repeat.value = true;
      errorToast(msg);
    }
  });
}
/**
 * 复制当前购物车
 */
function addGroup() {
  showLoading();
  if (!repeat.value) {
    return;
  }
  repeat.value = false;
  const payload = {
    user_id,
    bao_id: Number(borId.value),
  };
  toPublish('store/addTeamCart', payload, (obj: any) => {
    const { code, msg } = obj;
    if (code === 1) {
      repeat.value = true;
      successToast(msg);
      navTo('groupBenefits/groupEditor');
    } else {
      repeat.value = true;
      errorToast(msg);
    }
  });
}
function openBankPad() {
  PobulicePopup.value.open();
}
function closeBankPad() {
  PobulicePopup.value.close();
}
</script>

<style scoped lang="less">
@import url('../groupBenefits/less/GroupPackage.less');
</style>